// Copyright 2022 jeff.li. and/or its affiliates.

#include <gtest/gtest.h>
#include <tbir/runtime/algorithm/prefix_matcher.h>
#include <iostream>
#include <map>
#include <string>
#include <vector>

namespace tbir::runtime {

    TEST(PrefixMatcher, PrefixMatch) {
        std::set<std::string> test_data{
                "hello world",
                "happy",
                "world",
                "hi",
                "worldhi",
        };

        PrefixMatcher pm(test_data);
        std::string data("world");
        bool found = false;
        int len = pm.PrefixMatch(data, &found);
        ASSERT_TRUE(found);
        ASSERT_EQ(len, data.size());
        pm.PrefixMatch(std::string("je"), &found);
        ASSERT_FALSE(found);
        // TODO (mxd) : more test
        data = std::string("happy") + "world";
        auto match_len = pm.PrefixSearch(data.data(), data.size());
        ASSERT_EQ(match_len, 5);
    }

}  // namespace tbir::runtime
